package com.ruoyi.backend.controller.merchantRanking;

import com.ruoyi.backend.domain.Store;
import com.ruoyi.backend.service.IStoreService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商户管理Controller
 *
 * @author 王冰冰
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/merchantRanking")
public class StoreControllerMR extends BaseController {
    @Autowired
    private IStoreService storeService;

    /**
     * 查询商户管理列表
     */
    // @RequiresPermissions("storeManagement:merchantRanking:list")
    @GetMapping("/list")
    public TableDataInfo list(Store store) {
        startPage();
        List<Store> list = storeService.selectStoreListMR(store);
        return getDataTable(list);
    }

    /**
     * 导出商户管理列表
     */
    @RequiresPermissions("storeManagement:merchantRanking:export")
    @Log(title = "商户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Store store) {
        List<Store> list = storeService.selectStoreList(store);
        ExcelUtil<Store> util = new ExcelUtil<Store>(Store.class);
        util.exportExcel(response, list, "商户管理数据");
    }

    /**
     * 获取商户管理详细信息
     */
    @RequiresPermissions("storeManagement:merchantRanking:query")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId) {
        return success(storeService.selectStoreByStoreId(storeId));
    }

    /**
     * 新增商户管理
     */
    @RequiresPermissions("storeManagement:merchantRanking:add")
    @Log(title = "商户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Store store) {
        return toAjax(storeService.insertStore(store));
    }

    /**
     * 修改商户管理
     */
    @RequiresPermissions("storeManagement:merchantRanking:edit")
    @Log(title = "商户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Store store) {
        return toAjax(storeService.updateStore(store));
    }

    /**
     * 删除商户管理
     */
    @RequiresPermissions("storeManagement:merchantRanking:remove")
    @Log(title = "商户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds) {
        return toAjax(storeService.deleteStoreByStoreIds(storeIds));
    }
}